{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>考核项</legend>
    </fieldset>

    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show" style="float: left">
            <form class="layui-form"  method="get">
                <div style="float:left;">
                    <div class="layui-form-item" style="margin-left: -120px;">
                        <div class="layui-input-block" style="width: 210px;">
                            <select  class="form-control input-sm" lay-filter="status" aria-invalid="false" id="keywords" name="keywords">
                                <option value="0" disabled selected style="display:none">请选择考核项</option>
                                {foreach name="cate_list" item="val" key="key"}
                                <option value="{$val['cate_id']}" id="{$val['cate_id']}" name="keywords"  style="width:100%;" {if $keywords==$val.cate_id} selected {/if}>{$val['title']}</option>
                                {/foreach}
                            </select>
                            <div class="layui-input-block" style="width: 500px;margin-top: -38px;margin-left: 220px">
                                <div class="layui-inline" style="margin-right: 6px;">
                                    <div class="layui-btn-group layui-inline">
                                      <!--  <a  href="{:url('dayList')}" class="layui-btn layui-btn-primary">重置</a>-->
                                        <button id="search" class="layui-btn layui-btn-normal" type="button" lay-submit lay-filter="formDemo" style="background-color: #009688;">
                                            <i class="layui-icon">&#xe615;</i>查找
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <form class="layui-form layui-form-pane" lay-filter="form" id="form">

        <div  v-for="(item, index) in title_data">

            <div class="layui-form-item" v-if="item.type==1" >

                <div class="layui-input-6">
                   <span> {{index+1}}.</span><textarea style="padding-top: 10px;margin-top: -27px;padding-left: 10px;border: none;margin-left: 20px" readonly cols="200" rows="2" >{{item.title}}</textarea>
                </div>
            </div>
            <div class="layui-form-item" v-if="item.type==1" >
                <div class="layui-input-block" style="margin-left: 60px">
                     <span v-for="(item1, index1) in item.var_content">
                         <input :name="'timu'+item.title_id+'['+index1+']'" type="hidden" value="0">
                         <span v-if="item.answer" v-for="(item2, index2) in item.answer">

                              <input v-if="index2==index1 && item2==1" type="checkbox" lay-filter="ck" :id="'checkbox'+item.title_id+'['+index1+']'" :name="'timu'+item.title_id+'['+index1+']'" value="1" lay-skin="primary" :title="item1" checked>
                              <input v-if="index2==index1 && item2!=1" type="checkbox" lay-filter="ck" :id="'checkbox'+item.title_id+'['+index1+']'" :name="'timu'+item.title_id+'['+index1+']'" value="1" lay-skin="primary" :title="item1" >
                         </span>
                          <span v-if="item.answer==''">
                            <input  type="checkbox" lay-filter="ck" :id="'checkbox'+item.title_id+'['+index1+']'" :name="'timu'+item.title_id+'['+index1+']'" value="1" lay-skin="primary" :title="item1" >
                        </span>
                     </span>
                </div>
            </div>


            <div class="layui-form-item"  v-if="item.type==2">

                <div class="layui-input-6">
                    <span> {{index+1}}.</span><textarea readonly cols="200" rows="2" style="padding-top: 10px;margin-left: 20px;margin-top: -27px;padding-left: 10px;border: none">{{item.title}}</textarea>
                </div>
            </div>
            <div class="layui-form-item"  v-if="item.type==2">
                <div class="layui-input-block" style="margin-left: 60px">
                    <span v-for="(item4, key4,index4) in item.var_content">
                         <span v-if="item.answer" v-for="(item3, key3,index3) in item.answer">
                             <span v-if="key3==index4">
                                 {{item4}}:
                             </span>
                             <input v-if="key3==index4" type="text" :name="'timu'+item.title_id+'['+']'"  lay-skin="primary"  style="width: 30px;height: 20px;" :value="item3">
                             <span  style="margin-left: 30px;"></span>
                        </span>
                        <span v-if="item.answer==''">
                              {{item4}}:
                             <input type="text" :name="'timu'+item.title_id+'['+']'"  lay-skin="primary"  style="width: 30px;height: 20px;" >
                            <span  style="margin-left: 30px;"></span>
                        </span>

                    </span>
                </div>
            </div>

        </div>

    </form>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="save(1)">保存</button>
        <!--    <button class="layui-btn" onclick="save(2)">提交</button>-->
            <a href="{:url('lists')}" class="layui-btn layui-btn-primary">{:lang('back')}</a>
        </div>
    </div>
</div>
{include file="common/foot"/}
<script type="text/javascript" src="/static/common/js/vue.js"></script>
<script>

    //数据初始化
    var app = new Vue({
        el: '#form',
        data: {
            //分类
            title_data: [],
            cate_id:''
        },

    });
    layui.use(['form', 'layer'], function () {
        var form = layui.form, layer = layui.layer, $ = layui.jquery;
        form.render();



        //ajax请求数据
        $('#search').on('click', function () {

            var keywords = $('#keywords').val();
            app.cate_id = keywords;
            if ($.trim(keywords) === '') {
                layer.msg('{:lang("pleaseEnter")}查找信息！', {icon: 0});
                return;
            }
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: "{:url('title_show')}",
                data: {cate_id:keywords},
                success : function(res) {
                    if(res.code){
                        app.title_data = res.list;
                        setTimeout(function () {
                            form.render();
                        },500);
                    }else{
                        layer.msg(res.msg, {icon: 1});
                        app.title_data = '';
                        setTimeout(function () {
                            form.render();
                        },500);
                    }

                },
            });
        });
    });

    //保存
    function save(flag) {

        $.ajax({
            type: 'POST',
            url: "{:url('title')}?cate_id="+app.cate_id+'&flag='+flag+'&tab='+{$tab},
            data: $("#form").serialize(),
            success: function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1});
                    if(res.data==1){
                        location.href = "{:url(title)}";
                    }else if(res.data==2){
                        location.href = "{:url(term_title)}";
                    }
                    else if(res.data==3){
                        location.href = "{:url(year_title)}";
                    }

                }else{
                    layer.msg(res.msg,{icon:2});
                }

            },
            dataType: 'json'
        });

    }

</script>